package com.yckj.lawyermanager.dongao.controller;

import com.yckj.lawyermanager.dongao.entity.Lawyer;
import com.yckj.lawyermanager.dongao.service.LawyerService;

import java.util.List;

/**
 * @author wanghonwgei
 * @version 1.0
 * @date 2023/1/4 21:52
 */

@Controller
public class LawyerController {

    @Autowired
    LawyerService lawyerService;
    @RequestMapping("/modify")
    public  String modifyLawyer(Lawyer lawyer){
        lawyerService.modifyLawyer(lawyer);
        //return "../static/success";
        return "redirect:/show";
    }
    @RequestMapping("/getLawyer")
    public String getLawyerById(Model model,int lawyerid){
        Lawyer lawyer = lawyerService.findLawyerById(lawyerid) ;
        model.addAttribute("lawyer",lawyer);
        return "../static/modifyLawyer";
    }
    @RequestMapping("/del")
    public  String delLawyer(int lawyerid){
        lawyerService.removeLawyer(lawyerid);
        return "../static/success";
    }

    @RequestMapping("/show")
    public  String showLawyer(Model model){
        List<Lawyer> lawyerList = lawyerService.findLawyer();
        //把lawyerList传递到网页上
        model.addAttribute("lawList",lawyerList);
        //displayLawyer 代表网页displayLawyer.html
        return "../static/displayLawyer";
    }
    @RequestMapping("/addLawyer")
    public String addLawyer(Lawyer lawyer){
        lawyerService.addLawyer(lawyer);
        //success代表网页success.html
        return "../static/success";

    }
}

